package com.osexp.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class TaskQueue {
	List<Task> lTasks=null;
		
	public void currPrint() {
		System.out.println("ltask size:taksqueue.java===="+lTasks.size());
		for(Task t:lTasks){
			System.out.println(t);
		}
	}

	public void sort() {
		Collections.sort(lTasks, new TaskComparator());
	}
	
	public TaskQueue() {
		super();
		this.lTasks = new ArrayList<Task>();
	}

	public void add(int pid, Double dTime, int iLogicalAddress) {		
		Task task=new Task(pid, dTime, iLogicalAddress);
		lTasks.add(task);
	}
	
	public void add(int pid, List<trace> lt) {
		for(trace t:lt){
			Task task=new Task(pid, t.getdTime(), t.getiLogicalAddress());
			lTasks.add(task);
		}		
	}	
	
	public Task next(int idx) {			
		return lTasks.get(idx);		
	}
}

class TaskComparator implements Comparator<Task> {
	@Override
	public int compare(Task o1, Task o2) {
		if (o1.getdTime() > o2.getdTime())
			return 1;
		if (o1.getdTime() < o2.getdTime())
			return -1;
		else
			return 0;
	}
}
